package zho.remotecontrol;


import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import zho.remotecontrol.Util.GlideLoadUtils;
import zho.remotecontrol.gson.Surroundings;

/**
 * Created by zhodui on 2018/10/22.
 */

public class SurroundAdapter extends RecyclerView.Adapter<SurroundAdapter.ViewHolder>{
    private Context mcontext =null;
    private List<Surroundings> mSurroundList;

    public SurroundAdapter(List<Surroundings>comicList){
        mSurroundList = comicList;
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        CardView cardView;
        ImageView surroundImage;
        TextView surroundText;
        public ViewHolder(View view){
            super(view);
            cardView = (CardView)view;
            surroundImage = (ImageView)view.findViewById(R.id.surround_image);
            surroundText = (TextView)view.findViewById(R.id.surround_name);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(mcontext == null){
            mcontext = parent.getContext();
        }
        View view = LayoutInflater.from(mcontext).inflate(R.layout.surround_item,parent,false);
        final ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position =viewHolder.getAdapterPosition();
                Surroundings surrounding = mSurroundList.get(position);
//                Intent intent = new Intent(mcontext,Activity_comic.class);
//                intent.putExtra(Activity_comic.COMIC_NAME,comic.getName());
//                intent.putExtra(Activity_comic.COMIC_IMAGE_ID,comic.getImageId());
//                mcontext.startActivity(intent);
                Toast.makeText(mcontext,"点击场景",Toast.LENGTH_SHORT).show();
            }
        });
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Surroundings surrounding =mSurroundList.get(position);
        holder.surroundText.setText(surrounding.getName());
//        GlideLoadUtils glideLoadUtils = new GlideLoadUtils();
//        glideLoadUtils.glideLoad(mcontext,surrounding.getImageId(),holder.surroundImage,R.drawable.add);
//
        // Glide.with(mcontext).load(surrounding.getImageId()).into(holder.surroundImage);

    }
    @Override
    public int getItemCount() {
        return mSurroundList.size();
    }
}
